const router = require('express').Router()
// 引入 mockjs 模块
const Mock = require('mockjs')

// 添加学生信息
// 完整 url: http://127.0.0.1:3000/api/student/add
router.post('/add', (req, res, next) => {
  // .....TODO......
})

// 查询学生信息：分页查询
router.get('/find', (req, res, next) => {
  // 页码
  const { page } = req.query
  // 每页显示数据记录条数
  const pageSize = 20
  // Mock 查询到的学生数据
  const data = Mock.mock({
    "list|20": [
      {
        "stuNo|+1": (page - 1) * pageSize + 1,
        "name": '@cname(2,4)',
        "birth": "@date('yyyy-MM-dd')",
        "sex|+1": ['male', 'female']
      }
    ],
    "currentPage": page,
    "totalPages": 20
  })
  res.json({
    code: 200,
    data
  })
})

module.exports = router